import axios from 'axios'
import Vue from 'vue'

axios.defaults.baseURL = 'http://127.0.0.1:3000'
// axios.defaults.baseURL = 'http://120.26.187.228:3000'
axios.interceptors.request.use(
  config => {
    if (localStorage.Authorization) { // 判断token是否存在
      config.headers.Authorization = localStorage.studentNumber + ' ' + localStorage.Authorization // 将token设置成请求头
    }
    return config
  },
  err => {
    return Promise.reject(err)
  }
)

// http response 拦截器
axios.interceptors.response.use(res => {
  return res
}, (err) => {
  console.log(err)
})

Vue.prototype.$axios = axios
